<%@page import="itsm.isperp.framework.core.context.ContextHolder"%>
<%@ page pageEncoding="UTF-8"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="isperp" uri="/WEB-INF/tlds/isperp.tld"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
  String path = request.getContextPath();
			String basePath = ContextHolder.getWebServerName(request);
%>
<script type="text/javascript" src="<%=basePath%>js/libs/cityselect/jquery.cityselect.js"></script>
<form:form commandName="model" cssClass="validate" id="customerForm"
	action="customer/customer/save">
	<form:hidden path="id" />
	<form:hidden path="departmentId" />
	<form:hidden path="departmentName" />
	<input id="ctype" value="${type }" name="ctype" style="display:none"/>
	<div class="header">
		<h2>
			&nbsp;&nbsp;基本信息<span><font color="red">（* 为必填项）</font> </span>
		</h2>
	</div>
	<table class=" form-table">
		<tbody>
			<tr>
				<td class="td1">编号：</td>
				<td class="td2"><form:input path="code" cssClass="required"
						maxlength="40" /></td>
			</tr>
			<tr>
				<td class="td1">名称：</td>
				<td class="td2"><form:input path="name" cssClass="required"
						maxlength="200" cssStyle="width:60%" /></td>
			</tr>
			<%-- <tr>
				<td class="td1">名称：</td>
				<td class="td2"><form:input path="fullname" cssClass="required"
						maxlength="500" cssStyle="width:60%" /></td>
			</tr> --%>
           <c:if test="${type eq 1 }">
			<tr>
				<td class="td1">类型：</td>
				<td class="td2"><form:select path="type"
						items="${customer_type }" itemLabel="name" itemValue="name"
						cssStyle="width:60%" /></td>
			</tr>
		 </c:if>
			<tr style="display:none">
				<td class="td1">分类：</td>
				<td class="td2"><isperp:dictSelector id="category"
						codeValue="true" selectedValue="${model.category }"
						name="category" hasEmptyValue="false" typeCode="CUSTOMER_CATEGORY"></isperp:dictSelector>
				</td>
			</tr>
			<tr style="display:none">
				<td class="td1">状态：</td>
				<td class="td2"><isperp:dictSelector id="status"
						selectedValue="${model.status }" name="status"
						typeCode="CUSTOMER_STATUS"></isperp:dictSelector>
				</td>
			</tr>


			<tr style="display:none">
				<td class="td1">行业：</td>
				<td class="td2"><isperp:dictSelector id="industry"
						selectedValue="${model.industry }" name="industry"
						typeCode="CUSTOMER_INDUSTRY"></isperp:dictSelector>
				</td>
			</tr>
			</tr>
			<tr>
				<td class="td1">地区：</td>
				<td class="td2">
					<div id="city">
						<select class="prov" id="city1" name="province"></select> <select
							name="city" class="city" id="city2"></select> <select
							class="dist" id="city3" name="area"></select>
					</div></td>
			</tr>

			<tr style="display:none">
				<td class="td1">邮编：</td>
				<td class="td2"><form:input path="psotcode" maxlength="6"
						cssClass="number" max-length="6" />
				</td>
			</tr>
			<tr>
				<td class="td1">网站：</td>
				<td class="td2"><form:input path="website" maxlength="100"
						cssStyle="width:60%" />
				</td>
			</tr>
			<tr>
				<td class="td1">联系地址：</td>
				<td class="td2"><form:input path="address" maxlength="200"
						cssStyle="width:60%" />
				</td>
			</tr>

			<tr>
				<td class="td1">备注：</td>
				<td class="td2"><form:textarea path="memo" maxlength="500"
						cssStyle="width:60%" />
				</td>
			</tr>
		</tbody>
	</table>

	<div class="header">
		<h2>&nbsp;&nbsp;联系人信息</h2>
	</div>
	<table class=" form-table">
		<tbody>

			<tr>
				<td class="td1">联系人：</td>
				<td class="td2"><form:input path="linkman" maxlength="50"
						cssClass="" cssStyle="width:60%" /></td>
			</tr>
			<tr>

				<td class="td1">联系电话：</td>
				<td class="td2"><form:input path="linktel" cssClass=""
						maxlength="20" cssStyle="width:60%" />
				</td>
			</tr>

		</tbody>
	</table>

</form:form>
<c:if test="${empty hideBtn}">
	<isperp:buttonList>
		<button class="submit nui-mainbtn" onclick="isperp.submitForm();">保存</button>
	</isperp:buttonList>
</c:if>

<script type="text/javascript">
	function initProv() {
	    var turl="<%=basePath%>js/libs/cityselect/city.min.js";
		var tprov = '${model.province}';
		var tcity = '${model.city}';
		var tdist = '${model.area}';
		$("#city").citySelect({
			url : turl,
			prov : tprov, //省份  
			city : tcity, //城市  
			dist : tdist, //区县  
			nodata : "none" //当子集无数据时，隐藏select  
		});
	}

	$(function() {
		var departmentId = '${model.departmentId}';
		if (departmentId != "") {
			$("#relateDepartment").show();
		}
		if ('${model.code}' == '') {
			$
					.ajax({
						url : 'configuration/ci/getSeqByTableName?tableName=cus_customer',
						success : function(data) {
							if (data) {
								$("#code").val(data);
							}
						}
					});
		}
		initProv();
	});
	function sumbitForm() {
		isperp.submitForm({
			formId : "customerForm",
			success : function() {
				//callback($("#id").val(), $("#name").val());
				isperp.excuteParentFucByFuncName("createAfterSelectCustomer",
						"'" + $("#id").val() + "'" + ",'" + $("#name").val()
								+ "'");
				isperp.closeDialog();

			}
		});
	}
	function sumbitCusForm(callback) {
	    var linkman=$("#linkman").val();
	    var linktel=$("#linktel").val();
	    var address=$("#address").val();
		isperp.submitForm({
			formId : "customerForm",
			success : function() {
				callback($("#id").val(), $("#name").val());
			}
		});
	}
</script>

